﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using System.Text;

using SocialIn.Biz;
using SocialIn.Core.Data;


namespace SocialIn.Web.Search
{
    public partial class VoluntaryActivityDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["seq"] != null)
                    GetDefaultDataBind(Request.QueryString["seq"].ToString());
                //GetDefaultDataBind("6");
                
            }
        }


        protected void GetDefaultDataBind(string seq)
        {
            VoluntaryActivity biz = new VoluntaryActivity();

            #region 지원자 목록
            
            Result<DataTable> resultVolunteer = biz.GetVolunteerList(seq);

            if (resultVolunteer.ReturnValue != null && resultVolunteer.ReturnValue.Rows.Count > 0)
            {
                rptDrimiList.DataSource = resultVolunteer.ReturnValue;
                rptDrimiList.DataBind();

                //foreach (DataRow dr in resultVolunteer.ReturnValue.Rows)
                //{
                //    if (dr[""].Equals(""))
                //        btnApply.Visible = false;
                //}

                #region 감사 후기  : 완료 시에 만 로직을 수행한다.

                if (resultVolunteer.ReturnValue.Rows[0]["Complement"].ToString().Equals("1"))
                {
                    Result<DataTable> resultThanks = biz.GetVoluntaryAfterNote(seq);

                    if (resultThanks.ReturnValue != null && resultThanks.ReturnValue.Rows.Count > 0)
                    {
                        pnlComplete.Visible = true;
                        litThanks.Text = resultThanks.ReturnValue.Rows[0]["Comment"].ToString();
                    }
                }

                #endregion  

            }

            #endregion


            #region 본인이 지원을 했는지를 확인한다. 로그인 시에만 확인 할것!
            
            if (HttpContext.Current.Session[ConfigName.SessionMember] != null)
            {
                Member member = (Member)HttpContext.Current.Session[ConfigName.SessionMember];

                if (member != null)
                {
                    Result<DataTable> resultIsVolunteer = biz.GetIsVolunteer(seq);
                    if (resultIsVolunteer.ReturnValue != null && resultIsVolunteer.ReturnValue.Rows.Count > 0)
                    {
                        this.btnApply.Visible = false;
                    }
                }
            }
            else
            {
                btnApply.Visible = false;
            }

            #endregion
            
        }


        /// <summary>
        /// 드리미-봉사 지원하기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnApply_Click(object sender, EventArgs e)
        {
            VoluntaryActivity biz = new VoluntaryActivity();
            int iResult = biz.SetVolunteerApply(Request.QueryString["seq"].ToString());

            Page.RegisterStartupScript("error", "<script type='text/javascript'>alert('지원되었습니다. 감사합니다 ^^');</script>");
            Response.Redirect(string.Format("VoluntaryActivityDetail.aspx?seq={0}", Request.QueryString["seq"].ToString()));

        }
    }
}